//
//  WPMyMsgViewController.m
//  ZhongChouPingTai
//
//  Created by WeiPan on 16/4/4.
//  Copyright © 2016年 HuaYiSoftware. All rights reserved.
//

#import "WPMyMsgViewController.h"
#import "WPMsgTableViewCell.h"
#import "WPMsgModel.h"
static NSString *const kUITableViewCellIdentifier = @"cellIdentifier";

@interface WPMyMsgViewController ()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, strong) UILabel * noMoreLabel;/**< 没有说明 */
@property (nonatomic, strong) UITableView * msgTableView;/**< 消息列表 */
@property (nonatomic, strong) NSMutableArray * msgDatasource;/**< 消息数据源 */
- (void)initializeDataSource; /**< 初始化数据源 */
- (void)initializeUserInterface; /**< 初始化用户界面 */
- (void)refreshData;/**< 刷新数据 */

@end

@implementation WPMyMsgViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initializeDataSource];
    [self initializeUserInterface];
}
#pragma mark - init
- (void)initializeDataSource {
    self.msgDatasource = [NSMutableArray array];
    WPMsgModel * model = [WPMsgModel new];
    model.title = @"众筹提醒";
    model.time = @"下午 17：12：56";
    model.msgTitle = @"即将开始";
    model.posterImage = @"banner1";
    model.msgDetail = @"啊发发发发大家开发垃圾开了房间卡了积分冷风机冷风机浪费家里附近的垃圾费垃圾垃圾啦；积分垃圾费拉法基就垃圾积分解放军";
    model.top = @"请您按时取票！若由于个人原因，未能成功领取权益，后果自负。";
    [_msgDatasource addObject:model];
}
- (void)initializeUserInterface {
    [self.view addSubview:self.noMoreLabel];
    [self.view addSubview:self.msgTableView];
}
#pragma mark - 协议UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _msgDatasource.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    WPMsgTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kUITableViewCellIdentifier];
    if (!cell) {
        cell = [[WPMsgTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kUITableViewCellIdentifier];
    }
    cell.accessoryType = UITableViewCellAccessoryNone;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    [cell refreshDataWithMsgModel:_msgDatasource[indexPath.row]];
    return cell;
}
#pragma mark - UITableViewDelegate
//设置每一行高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 140*DHFlexibleHorizontalMutiplier();
}

//用户点击了某一行
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
}

#pragma mark -getter
- (UILabel *)noMoreLabel {
    if (!_noMoreLabel) {
        _noMoreLabel = ({
            UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, SCREEN_SIZE.width, 30*DHFlexibleHorizontalMutiplier())];
            lab.center = self.view.center;
            lab.font = [UIFont systemFontOfSize:12*DHFlexibleHorizontalMutiplier()];
            lab.textAlignment = NSTextAlignmentCenter;
            lab.text = @"您暂时没有消息记录";
            lab;
        });
    }
    return _noMoreLabel;
}
- (UITableView *)msgTableView {
    if (!_msgTableView) {
        _msgTableView = ({
            UITableView * tableview = [[UITableView alloc]initWithFrame:CGRectMake(0, navBar_Fheight, SCREEN_SIZE.width, SCREEN_SIZE.height - navBar_Fheight) style:UITableViewStylePlain];
            tableview.dataSource = self;
            tableview.delegate = self;
            tableview.tableFooterView = [UIView new];
            tableview.pagingEnabled = NO;
            tableview.bounces = NO;
            tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
            tableview.backgroundColor = [UIColor clearColor];
            tableview;
        });
    }
    return _msgTableView;
}
@end
